package com.cx.common.utils;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @Author:cxy
 * @Date:2019/10/24 15:11
 */
public class New {

	public static <T> List<T> arrayList() {
		List<T> list = new ArrayList<T>();
		return list;
	}

	public static <T> List<T> arrayList(Collection<T> collection) {
		List<T> list = new ArrayList<T>(collection);
		return list;
	}

	public static <T> List<T> arrayList(int capacity) {
		List<T> list = new ArrayList<T>(capacity);
		return list;
	}

	public static <T> Set<T> hashSet() {
		Set<T> set = new HashSet<T>();
		return set;
	}

	public static <T> Set<T> hashSet(int capacity) {
		Set<T> set = new HashSet<T>(capacity);
		return set;
	}

	public static <T> Set<T> hashSet(Collection<T> collection) {
		Set<T> set = new HashSet<T>(collection);
		return set;
	}

	public static <K, V> Map<K, V> hashMap() {
		return new HashMap<K, V>();
	}

	public static <K, V> Map<K, V> hashMap(Map<K, V> map) {
		return new HashMap<K, V>(map);
	}

	public static <K, V> Map<K, V> hashMap(int capacity) {
		return new HashMap<K, V>(capacity);
	}

	/**
	 * 有序的Map
	 *
	 * @return
	 */
	public static <K, V> LinkedHashMap<K, V> linkedHashMap() {
		return new LinkedHashMap<K, V>();
	}

	/**
	 * 有序的Map
	 * 
	 * @return
	 */
	public static <K, V> LinkedHashMap<K, V> linkedHashMap(int capacity) {
		return new LinkedHashMap<K, V>(capacity);
	}

	/**
	 * 线程安全的map
	 * 
	 * @return
	 */
	public static <K, V> Map<K, V> concurrentHashMap() {
		return new ConcurrentHashMap<K, V>();
	}

	/**
	 * 线程安全的Set
	 * 
	 * @return
	 */
	public static <T> Set<T> safeSet() {
		Set<T> set = Collections.newSetFromMap(new ConcurrentHashMap<T, Boolean>());
		// Set<T> set = Collections.synchronizedSet(new HashSet<T>());
		return set;
	}

	/**
	 * 双向Map,非线程安全的
	 * 
	 * @return
	 */
	public static <K, V> BiMap<K, V> hashBiMap() {
		BiMap<K, V> map = HashBiMap.create();
		return map;
	}

	public static <K, V> BiMap<K, V> hashBiMap(int capacity) {
		BiMap<K, V> map = HashBiMap.create(capacity);
		return map;
	}

	public static <K, V> BiMap<K, V> hashBiMap(Map<K, V> map) {
		BiMap<K, V> biMap = HashBiMap.create(map);
		return biMap;
	}

}
